package jnpf.example.dubboservice;

import jnpf.base.UserInfo;
import jnpf.entity.ContractEntity;
import jnpf.provider.example.ContractProvider;
import jnpf.service.ContractService;
import jnpf.util.UserProvider;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司（https://www.jnpfsoft.com）
 * @date 2021-06-21
 */
@DubboService
public class ContractProviderImpl implements ContractProvider {
    @Autowired
    private ContractService contractService;
    @Autowired
    private UserProvider userProvider;

    @Override
    public ContractEntity getInfo(String id) {
        /** 获取传递过来的值 */
        String token = RpcContext.getContext().getAttachment("Authorization");
        //通过token获取当前登录信息
        UserInfo userInfo = userProvider.get(token);
        /** 使用dubbo传输的类必须序列化 */
        ContractEntity entity = contractService.getInfo(id);
        return entity;
    }
}
